/*
 * AdminServiceImpl.java
 *
 * Created on October 1, 2008, 10:15 PM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package org.vacuela.publishmx.services;

import java.util.List;
import org.vacuela.publishmx.context.ServiceContext;
import org.vacuela.publishmx.domains.User;

/**
 *
 * @author nestor.carrasco
 */
public class AdminServiceImpl extends AbstractDaoBasedPublish implements AdminService{
    public void saveUpdateUser(ServiceContext context) {
        User userDomain  = (User)context.getAttribute("userDomain");
        userDao.saveUpdate(userDomain);
    }

    public void getUserById(ServiceContext context) {
        Integer userId = (Integer)context.getAttribute("userId");
        User userDomain = userDao.getUser(userId);
        context.setAttribute("userDomain",userDomain);
    }

    public void getUserList(ServiceContext context) {
        List<User> userList = userDao.getUserList();
        context.setAttribute("userList", userList);
    }

    public void getUserByPassword(ServiceContext context) {
        String userId = (String)context.getAttribute("userId");
        String password = (String)context.getAttribute("password");
        User userDomain = userDao.getByUserAndPassword(userId,password);
        context.setAttribute("userDomain",userDomain);
    }

    public void searchUserByName(ServiceContext context) {
        String criteria = (String)context.getAttribute("criteria");
        List<User> userList = userDao.findUserByName(criteria);
        context.setAttribute("userList", userList);
    }
    
    public void deleteUser(ServiceContext context){
        String userId = (String)context.getAttribute("userId");
        boolean status = userDao.deleteUser(new Integer(userId));
        String message ="";
        if ( status ){
            message ="The User was removed sucessfully";
        }else{
            message ="There was a issue in Delete User";
        }
        context.setAttribute("message", message);
    }
}
